<template>
	<view class="">
		<view class="classify" :style="{height:searchHeight+'px'}">
			<!-- 侧边导航栏 -->
			<scroll-view class="nav" scroll-y="true" scroll-with-animation>
				<view :class="['nav_item', navindex == index ? 'nav_item_choose' : '']" 
				v-for="(item, index) in classList" @tap="changenav(index,item)" :key="index">
					{{item.name}}
					<view class="line">
					</view>
				</view>
			</scroll-view>
				<!-- <scroll-view scroll-y="true" class="nav">
					<view :class="['nav_item',navindex == index ? 'nav_item_i': '']" v-for="(item, index) in navList " :key="index" @tap="oneclassify(index)">
						<view class="nav_item_title">
							{{item.navtitle}}
						</view>
						<view v-if="navindex == index" 
						@tap="changetwoclassify(key)"
						:class="['nav_item_two', navtwoindex == key ? 'nav_item_two_i':'']" 
						v-for="(items,key) in item.classTwo" :key="key">
							{{items.title}}
						</view>
					</view>
				</scroll-view> -->
				<!-- 右侧商品 -->
				<view class="product">
					<view class="product-con">
						<view class="product_banner">
							<image :src="prcImage" mode="aspectFill"></image>
						</view>
						<view class="nav1">
							<!-- <view :class="['product_nav_item', productnavCurrent == choosetab.index? 'product_nav_item_current':'' ]" v-for=" (choosetab,index) in productnav" :key="index" @tap="chooseChange(index)">
								{{choosetab.title}}
								<view class="" v-if="choosetab.index == 2">
									<image v-if="productnavCurrent == index"  :src="choosetab.pic2" mode=""></image>
									<image v-else :src="choosetab.pic1" mode=""></image>
								</view>
								<view class="" v-else></view>
							</view> -->
							<view :class="['nav_item1', navind == index? 'nav_item_item1': '']" @tap="changenavInd(index)" v-for="(item, index) in productnav" :key="index">
								{{item.title}}
								<view class="p-box" v-if="navind == 2 && item.title == '价格'" :style="{marginTop:version ? '10rpx' : ''}">
									<image v-if="priceOrder === 0 && navind != 2" :src="Url+'add_images/price-ud.png'" mode="widthFix"></image>
									<image v-if="priceOrder === 1 && navind === 2" :src="Url+'add_images/price-up.png'" mode="widthFix"></image>
									<image v-if="priceOrder === 2 && navind === 2" :src="Url+'add_images/price-down.png'" mode="widthFix"></image>
									<!-- <text :class="{active: priceOrder === 1 && navind === 2}" class="icon-shang"></text>
									<text :class="{active: priceOrder === 2 && navind === 2}" class="icon-shang xia"></text> -->
								</view>
							</view>
						</view>
					</view>
					<scroll-view scroll-y="true"  class="product_list" :style="{height:classifyHei+'px'}" @scrolltolower="$emit('scrollBottom')">
						<view v-if="goodList.length">
							<view class="product1">
								<view class="list" v-for="(item, index) in goodList" @tap="$emit('todetail',item)" :key="index">
									<view class="pic">
										<image :src="item.cover" mode="aspectFill"></image>
										<view v-if="item.tags_name" class="sc-tour-li-tags" ><text>{{item.tags_name}}</text></view>
									</view>
									<view class="info">
										<view class="info_title-over">{{item.name}}</view>
										<!-- <view class="desc" v-if="descShow">{{item.size_info}}</view> -->
										<view class="volume volume-font"><image :src="Url+'add_images/ic-hot.png'" mode="widthFix"></image>销量:{{item.show_sales}}</view>
										<view class="price clearfix">
											<view class="">
												<text class="price_now">{{item.price}}</text>
												<text class="price_line" v-if="item.cost_price">￥{{item.cost_price}}</text>
												<text class="price_line" v-else></text>
											</view>
										</view>
										<view v-if="!item.num" class="addcart" @tap.stop="$emit('todetail',item)"><image :src="Url+'add_images/ic-add.png'" mode=""></image></view>
										<!-- <slot @tap="change(index,key)" name="add_delet"></slot> -->
									</view>
								</view>
							</view>
							<uni-load-more :loadingType="con.loadingType" :contentText="con.contentText"></uni-load-more>
						</view>
						<sc-no v-else width="20%"></sc-no>
					</scroll-view>
				</view>
		</view>
	</view>
</template>

<script>
	import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
	import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
	import product from '@/components/classify/product.vue'
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		props:{
			searchHeight:{
				type:Number
			},
			classList:{
				type:Array
			},
			goodList:{
				type:Array
			},
			con:{
				type:Object,
				default:{
					loadingType: 0,//定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
					contentText: {
						contentdown:'上拉加载更多',
						contentrefresh: '正在加载...',
						contentnomore: '到底了~',
					},
				}
			}
		},
		components: {uniCollapse,uniCollapseItem ,product,uniLoadMore},
		data () {
			return {
				navindex: 0,
				navind:0,
				navtwoindex: 0,
				arrangeflag: true,
				Url:this.Imgurl,
				productnav: [
					{
						title: '综合',
						pic1: this.Imgurl+'mine/index/classify01.png',
						pic2: this.Imgurl+'mine/index/classify11.png',
						index:0
					},
					{
						title: '销量',
						pic1: this.Imgurl+'mine/index/classify02.png',
						pic2: this.Imgurl+'mine/index/classify12.png',
						index:1
					},
					{
						title: '价格',
						pic1: this.Imgurl+'mine/index/classify02.png',
						pic2: this.Imgurl+'mine/index/classify12.png',
						index:2
					}
				],
				productnavCurrent:0,
				classifyHei:0,
				priceOrder:0,
				prcImage:'',
				version:uni.getSystemInfoSync().version
			}
		},
		created() {
			this.prcImage = this.classList[0].icon;
		},
		mounted() {
			var that = this;
			var version = uni.getSystemInfoSync().version;
			this.$nextTick( ()=> {
				if(!version){
					const query = uni.createSelectorQuery()
					query.select('.product_banner').boundingClientRect(data => {
						// 若消息体没有超过2倍的键盘则向下移动差值,防止遮住消息体
						// console.log(data)
						try{
							that.classifyHei = that.searchHeight - data.height;
							// console.log('打撒',that.classifyHei)
						}catch(e){
							//TODO handle the exception
							console.log(e)
						}
					}).exec();
				}else{
					var observer = uni.createIntersectionObserver(this);
						observer.relativeTo('.product').observe('.product-con', (res) => {
						   // console.log('observer',res)
						   let height = res.boundingClientRect.height;
						   that.classifyHei = that.searchHeight - height;
					})
				}
			    // Code that will run only after the
			    // entire view has been rendered
			})
		},
		methods: {
			changenavInd(index) {
				this.navind = index
				if (index == 2) {
					this.priceOrder = this.priceOrder == 1 ? 2 : 1
				}else{
					this.priceOrder = 0;
				}
				this.$emit('change',index,this.priceOrder)
			},
			changenav (index,item) {
				// console.log(1);
				this.navindex = index;
				this.prcImage = item.icon;
				this.$emit('classfly',item)
				// this.scrollTop == this.arr[index] ? this.scrollTop = this.scrollTop+2 : this.scrollTop = this.arr[index]//防止两次相等造成点击不触发滚动时间
				// console.log(this.scrollTop);
			},
			oneclassify (index) {
				this.navindex = index
			},
			changetwoclassify (key) {
				this.navtwoindex = key
			},
			chooseChange(index){
				this.productnavCurrent = index
				if(index == 2) {
					this.arrangeflag = !this.arrangeflag
				}
			}
			
		}
	}
</script>

<style lang="less" scoped>
	.nav1 {
		width: 100%;
		height: 84upx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		padding: 20upx 0;
		border-bottom: 2upx solid #F9F9F9;
		background-color: #FFFFFF;
	
		.nav_item1 {
			flex: 1;
			height: 32upx;
			font-size: 28upx;
			color: #333333;
			text-align: center;
			line-height: 32upx;
			display: flex;
			align-items: center;
			justify-content: center;
	
			// image {
			// 	width: 28upx;
			// 	height: 28upx;
			// 	margin-left: 8upx;
			// 	vertical-align: middle;
			// }
		}
	
		.nav_item_item1 {
			color: #FF2842;
		}
	}
	.p-box {
		// display: flex;
		// flex-direction: column;
		margin-left: 10upx;
		image{
			width:15upx;
			height: 23upx;
		}
	
		.icon-shang {
			display: inline-block;
			width: 10upx;
			height: 10upx;
			margin-left: 10upx;
			border-top: 2upx solid #888;
			border-left: 2upx solid #888;
			transform: rotate(45deg);
	
			&.active {
				border-top: 2upx solid red;
				border-left: 2upx solid red;
			}
		}
	
		.xia {
			transform: rotate(-135deg);
		}
	}
	.classify {
		display: flex;
		justify-content: space-between;
	}
	.nav {
		width: 25%;
		margin-right: 10px;
		border-right: 1px solid #F9F9F9;
	}
	.nav_item {
		background-color: #FFFFFF;
		width: 100%;
		height:100upx;
		font-size: 24upx;
		color: #333333;
		padding-left: 30upx;
		box-sizing: border-box;
		line-height: 100upx;
	}
	.nav_item_choose {
		background-color: #f9f9f9;
		position: relative;
		color: #FF2842;
		font-weight: bold;
		.line {
			width: 6upx;
			height:28upx;
			background-color: #FF2842;
			position: absolute;
			left: 0;
			top: 50%;
			transform: translateY(-50%);
		}
	}
	.product {
		width: 75%;
		padding-right: 15upx;
		height: 100%;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		.product_banner {
			width: 560upx;
			height: 164upx;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.product_nav {
			width: 100%;
			height: 64upx;
			padding-top: 6upx;
			border-bottom: 2upx solid #F9F9F9;
			display: flex;
			align-items: center;
			justify-content: space-around;
			box-sizing: border-box;
			.product_nav_item {
				flex: 1;
				text-align: center;
				height: 36upx;
				font-size: 24upx;
				line-height: 36upx;
				// border-right: 2upx solid #E1E1E1;
				display: flex;
				align-items: center;
				justify-content: center;
				image {
					width: 28upx;
					height: 28upx;
					margin-left: 8upx;
					vertical-align: middle;
				}
			}
			.product_nav_item_1 {
				flex: 1;
				text-align: center;
				height: 36upx;
				font-size: 24upx;
				line-height: 36upx;
				border-right: 2upx solid #E1E1E1;
			}
			.product_nav_item_current{
				color: #FF2842;
			}
			.product_nav_item:last-child {
				border-right: none;
			}
		}
		.product_list {
			height: 950upx;
		}
	}
	.product1 {
		background-color: #ffffff;
		padding: 0 26upx;
		box-sizing: border-box;
	}
	.info_title-over{
		// height:70upx;
		font-size: 28upx;
		color: #333333;
		line-height:35upx;
		    text-overflow: ellipsis;
		    white-space: nowrap;
			display: block;
			overflow: hidden;
			max-width:280upx;
	}
	.list {
		width: 100%;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
				padding: 30upx 0;
				.sc-tour-li-tags{
					position: absolute;
					top: 0;
					left:5%;
					width: 65upx;
					height: 64upx;
					font-size: 18upx;
					color: #FFFFFF;
					word-wrap: break-word;
					word-break: break-all;
					text-align: center;
					background-image: url('https://jy-shops.oss-cn-beijing.aliyuncs.com/client/image/add_images/sc-tags.png');
					background-size: cover;
					z-index: 10;
					transform-origin: 0 0;
					padding: 0 10upx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;
					flex-wrap: wrap;
					transform: scale(0.8,0.8);
					&.top{
						top: 20upx;
					}
					text{
						transform: scale(0.8,0.8);
						line-height: 1.3;
					}
				}
		.pic {
			width: 180upx;
			height:180upx;
			margin-right:30upx;
			border-radius: 10upx;
			overflow: hidden;
			position: relative;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.info {
			flex: 1;
			position: relative;
			box-sizing: border-box;
			border-bottom: 2upx solid #F9F9F9;
			padding-bottom: 20upx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			min-height:213upx;
			justify-content: space-between;
			.info_tilte {
				height: 80upx;
				font-size: 28upx;
				color: #333333;
				line-height: 40upx;
				text-overflow: ellipsis;
				white-space: nowrap;
				display: block;
				overflow: hidden;
				max-width:280upx;
				// height: 80upx;
			}
			.desc {
				font-size: 22upx;
				color: #999999;
				line-height: 32upx;
			}
			.volume {
				font-size: 20upx;
				color: #999;
				// margin: 10upx 0;
			}
			.volume-font{
				padding: 8upx 17upx;
				box-sizing: border-box;
				background:rgba(255,40,66,0.04);
				border-radius:4upx;
				color: #FF2842;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					width:25upx;
					height: 25upx;
					margin-right:10upx;
				}
			}
			.standard {
				display: inline-block;
				height: 40upx;
				background-color: #f9f9f9;
				color: #999999;
				padding: 0 10upx;
				box-sizing: border-box;
				border-radius: 8upx;
				line-height: 40upx;
				font-size: 24upx;
				margin-bottom:10upx;
			}
			.price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				line-height: 44upx;
				width: 100%;
				.price_now {
					font-size: 28upx;
					color: #FF2842;
					line-height: 40upx;
					line-height: 28upx;
					margin-right: 10upx;
					font-weight: bold;
					&::before{
						content:'￥';
						display: inline-block;
						font-size: 20upx;
						font-weight: 400;
					}
				}
				.price_line {
					font-size:18upx;
					// line-height: 24upx;
					color: #999;
					height: 32upx;
					line-height: 40upx;
					text-decoration: line-through;
				}
				.num {
					font-size: 28upx;
					color: #999999;
					line-height: 28upx;
					margin-top: -8upx;
				}
			}
			.addcart {
				position: absolute;
				bottom:18upx;
				right: 0;
				width:44upx;
				height:44upx;
				
				image {
					width: 100%;
					height: 100%;
				}
			}
			.add_delet {
				position: absolute;
				bottom: 20upx;
				right: 0;
				z-index: 9;
				.delet {
					text-align: right;
					.icon {
						font-size: 28upx;
						color: #999999;
					}
				}
				.add {
					.icon {
						font-size: 28upx;
						color: #999999;
					}
					text {
						font-size: 28upx;
						margin: 0 10upx;
					}
				}
			}
		}
	}
	.list:last-child .info {
		border-bottom: none;
	}
</style>
